<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>高阶函数</title>
</head>
<body>
    <script>

        function breathe(amount) {
            return new Promise((resolve,reject) => {
                if(amount < 500) {
                    reject('That is to small of a value');
                }
                setTimeout( () => resolve(`Done for ${amount} ms`),amount)
            })
        }

        breathe(200).then(res=>{
            
        })

        async function go(name,last) {
            console.log(name,list);
            let res = await breathe(10000);
            console.log(res);
            res = await breathe(300);
            console.log(res);
            res = await breathe(750);
            console.log(res);
            res = await breathe(900);
            console.log(res);


        }

        function catchErrors(fun){
            console.log('----');
            return function(...args) {
                console.log(args);

                return fun(...args).catch( err => {

                });
            }
        }

        const wrappedFunction = catchErrors(go);

        wrappedFunction('eee','ddss');

    </script>
</body>
</html>